
* 1) create boardex_empl only for directors that are CEOs 
* 2) create ISS treatment at the firm level
* 3) create ISS treatment at the TN4 level (network)

cd "`c(pwd)'"   // Set working directory to wherever the user placed "replication_package"

* Define global paths relative to the main directory
global main_dir "`c(pwd)'"
global data_dir "$main_dir/data_analysis"
global rawdata_dir "$main_dir/data_raw"
global tables_dir "$main_dir/tables"

cd "$rawdata_dir/"

use boardex_02, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_02_CEO.dta, replace

use boardex_04, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_04_CEO.dta, replace

use boardex_06, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_06_CEO.dta, replace

use boardex_08, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_08_CEO.dta, replace

use boardex_10, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_10_CEO.dta, replace

use boardex_12, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_12_CEO.dta, replace

use boardex_14, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_14_CEO.dta, replace

use boardex_16, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_16_CEO.dta, replace

use boardex_18, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_18_CEO.dta, replace

use boardex_20, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_20_CEO.dta, replace

use boardex_22, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_22_CEO.dta, replace

use boardex_24, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_24_CEO.dta, replace

use boardex_26, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_26_CEO.dta, replace

use boardex_28, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_28_CEO.dta, replace

use boardex_30, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_30_CEO.dta, replace

use boardex_32, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_32_CEO.dta, replace

use boardex_34, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_34_CEO.dta, replace

use boardex_36, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_36_CEO.dta, replace

use boardex_38, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_38_CEO.dta, replace

use boardex_40, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_40_CEO.dta, replace

use boardex_42, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_42_CEO.dta, replace

use boardex_44, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_44_CEO.dta, replace

use boardex_46, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_46_CEO.dta, replace

use boardex_48, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_48_CEO.dta, replace

use boardex_50, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_50_CEO.dta, replace

use boardex_52, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_52_CEO.dta, replace

use boardex_54, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_54_CEO.dta, replace

use boardex_56, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_56_CEO.dta, replace

use boardex_58, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_58_CEO.dta, replace

use boardex_60, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_60_CEO.dta, replace

use boardex_62, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_62_CEO.dta, replace

use boardex_64, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_64_CEO.dta, replace

use boardex_66, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_66_CEO.dta, replace

use boardex_68, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_68_CEO.dta, replace

use boardex_70, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_70_CEO.dta, replace

use boardex_72, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_72_CEO.dta, replace

use boardex_74, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_74_CEO.dta, replace

use boardex_76, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_76_CEO.dta, replace

use boardex_78, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_78_CEO.dta, replace

use boardex_80, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_80_CEO.dta, replace

use boardex_82, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_82_CEO.dta, replace

use boardex_84, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_84_CEO.dta, replace

use boardex_86, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_86_CEO.dta, replace

use boardex_88, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_88_CEO.dta, replace

use boardex_90, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_90_CEO.dta, replace

use boardex_92, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_92_CEO.dta, replace

use boardex_94, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_94_CEO.dta, replace

use boardex_96, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_96_CEO.dta, replace

use boardex_98, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_98_CEO.dta, replace

use boardex_100, clear
drop if brdposition=="No"
gen rolename2 = strupper(rolename)
gen ceo=0
replace ceo=1 if strpos(rolename2,"CEO")>0
replace ceo=1 if strpos(rolename2,"CHIEF EXEC")>0
keep if ceo==1
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
gen CEO=1
save boardex_empl_100_CEO.dta, replace


use boardex_empl_02_CEO
append using boardex_empl_04_CEO
append using boardex_empl_06_CEO
append using boardex_empl_08_CEO
append using boardex_empl_10_CEO
append using boardex_empl_12_CEO
append using boardex_empl_14_CEO
append using boardex_empl_16_CEO
append using boardex_empl_18_CEO
append using boardex_empl_20_CEO
append using boardex_empl_22_CEO
append using boardex_empl_24_CEO
append using boardex_empl_26_CEO
append using boardex_empl_28_CEO
append using boardex_empl_30_CEO
append using boardex_empl_32_CEO
append using boardex_empl_34_CEO
append using boardex_empl_36_CEO
append using boardex_empl_38_CEO
append using boardex_empl_40_CEO
append using boardex_empl_42_CEO
append using boardex_empl_44_CEO
append using boardex_empl_46_CEO
append using boardex_empl_48_CEO
append using boardex_empl_50_CEO
append using boardex_empl_52_CEO
append using boardex_empl_54_CEO
append using boardex_empl_56_CEO
append using boardex_empl_58_CEO
append using boardex_empl_60_CEO
append using boardex_empl_62_CEO
append using boardex_empl_64_CEO
append using boardex_empl_66_CEO
append using boardex_empl_68_CEO
append using boardex_empl_70_CEO
append using boardex_empl_72_CEO
append using boardex_empl_74_CEO
append using boardex_empl_76_CEO
append using boardex_empl_78_CEO
append using boardex_empl_80_CEO
append using boardex_empl_82_CEO
append using boardex_empl_84_CEO
append using boardex_empl_86_CEO
append using boardex_empl_88_CEO
append using boardex_empl_90_CEO
append using boardex_empl_92_CEO
append using boardex_empl_94_CEO
append using boardex_empl_96_CEO
append using boardex_empl_98_CEO
append using boardex_empl_100_CEO

cd "$data_dir/"
save boardex_empl_CEO.dta, replace


******************************************************************************
* identify the directors that are treated by the rule in 2003
use boardex_empl, clear
joinby year directorid gvkey using boardex_empl_CEO, unmatched(master)
replace CEO=0 if CEO==.
drop _merge
order  year directorid gvkey 
sort  year directorid gvkey 
bys year directorid: gen num=_n
by year directorid: egen num_boards = max(num) 
sum num_boards, det
sort year gvkey directorid num_boards
order year gvkey directorid num_boards
gen iss_treat=0 if year==2003
replace iss_treat=1 if num_boards>6 & num_boards<=12 & year==2003
replace iss_treat=1 if CEO==1 & num_boards>3  & num_boards<=12 & year==2003
sum iss_treat
sum iss_treat if year==2003
tab  iss_treat if year==2003
sort gvkey year
collapse (max) iss_treat, by (gvkey year)
sum iss_treat
sum iss_treat if year==2003
sort gvkey iss_treat
by gvkey: replace iss_treat=iss_treat[_n-1] if iss_treat==. & iss_treat[_n-1]!=.
save bygvkey_ISStreat, replace
******************************************************************************
* Network level TREATMENT
use tnic4_data, clear
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
joinby gvkey year using bygvkey_ISStreat, unmatched(master)
drop _merge
rename gvkey gvkey2
keep gvkey1 gvkey2 year iss_treat
bys gvkey1 year: egen ISStreattn4=mean(iss_treat)
rename gvkey1 gvkey
drop gvkey2
collapse (mean)  ISStreattn4, by(year gvkey)
save avgISStreattn4, replace



